package cn.xiongxf.feign;

import cn.xiongxf.result.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component  // 交给Spring容器管理
public class MediaFeignClientFallbackFactory implements FallbackFactory<MediaFeignClient> {
    @Override
    public MediaFeignClient create(Throwable throwable) {
        // 打印接口错误，方便查找错误
        throwable.printStackTrace();
        return new MediaFeignClient() {
            @Override
            public JsonResult selectByCourseId(Long courseId) {
                return JsonResult.error("触发熔断，媒体服务不可用，请稍后再试！");
            }
        };
    }
}
